package com.hxm.meizi.provider;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxm.meizi.R;
import com.hxm.meizi.entity.EveryDay;
import com.hxm.meizi.listener.OnItemClickListener;

import me.drakeet.multitype.ItemViewProvider;

/**
 * Created by hxm on 2017/2/19.
 */

public class AllProvider extends ItemViewProvider<EveryDay, AllProvider.AllHolder> {
    private OnItemClickListener listener;

    public AllProvider(OnItemClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected AllHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_all_provider, parent, false);
        return new AllHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull AllHolder holder, @NonNull final EveryDay everyDay) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener != null) {
                    listener.click(everyDay.getUrl());
                }
            }
        });
        holder.date.setText(everyDay.getDate());
        holder.title.setText(everyDay.getTitle());
    }

    static class AllHolder extends RecyclerView.ViewHolder {

        private TextView title, date;

        public AllHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.tv_title);
            date = (TextView) itemView.findViewById(R.id.tv_date);
        }
    }
}
